home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_08 / saks / strtst3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-12  |  1.7 KB  |  81 lines

  1. Listing 3 - A test program for a queue of void * used as a queue of str
  2.  
  3. //
  4. // strtst3.cpp - test genq3 using str elements
  5. //
  6.  
  7. #include <iostream.h>
  8.  
  9. #include "genq3.h"
  10. #include "showheap.h"
  11. #include "str.h"
  12.  
  13. #define DIM(a) (sizeof(a)/sizeof(a[0]))
  14.  
  15. void print_str(void *e)
  16.     {
  17.     cout << " " << *(str *)e;
  18.     }
  19.  
  20. void test()
  21.     {
  22.     char c;
  23.     size_t qn;
  24.     str qe;
  25.     str *pqe;
  26.     void *pv;
  27.     genq q[4];
  28.     while (cin >> c)
  29.         {
  30.         showheap();
  31.         if (c == 'q')
  32.             break;
  33.         if (c == 'a')
  34.             {
  35.             cin >> qn >> qe;
  36.             if (qn >= DIM(q))
  37.                 cout << "no such queue\n";
  38.             else
  39.                 q[qn].append(new str(qe));
  40.             }
  41.         else if (c == 'c')
  42.             {
  43.             cin >> qn;
  44.             if (qn >= DIM(q))
  45.                 cout << "no such queue\n";
  46.             else
  47.                 q[qn].clear();
  48.             }
  49.         else if (c == 'r')
  50.             {
  51.             cin >> qn;
  52.             if (qn >= DIM(q))
  53.                 cout << "no such queue\n";
  54.             else if (q[qn].remove(pv))
  55.                 {
  56.                 pqe = (str *)pv;
  57.                 cout << "removed " << *pqe << '\n';
  58.                 delete pqe;
  59.                 }
  60.             else
  61.                 cout << "q[" << qn << "] is empty\n";
  62.             }
  63.         else
  64.             continue;
  65.         for (size_t i = 0; i < DIM(q); ++i)
  66.             {
  67.             cout << i << ':';
  68.             q[i].apply(print_str);
  69.             cout << "\n";
  70.             }
  71.         }
  72.     }
  73.  
  74. int main()
  75.     {
  76.     showheap();
  77.     test();
  78.     showheap();
  79.     return 0;
  80.     }
  81.